package com.qimen.controller;

import java.net.InetAddress;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Stream;
import javax.servlet.http.HttpServletRequest;

import com.qimen.bean.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qimen.mapper.BajieMapper;
import com.qimen.mapper.HuajiaziMapper;
import com.qimen.mapper.RiliMapper;

@RestController
public class QimenController {

	@Autowired
	private RiliMapper riliMapper;
	@Autowired
	private BajieMapper bajieMapper;
	@Autowired
	private HuajiaziMapper huajiaziMapper;
	public String[] yangshen = new String[] { "值符", "螣蛇", "太阴", "六合", "白虎", "玄武", "九地", "九天" };
	public String[] yinshen = new String[] { "值符", "九天", "九地", "玄武", "白虎", "六合", "太阴", "螣蛇" };
	// public String[] yangmen = new String[] {"休","生","伤","杜","景","死","惊","开"};
	// public String[] yinmen = new String[] {"休","生","伤","杜","景","死","惊","开"};
	static String xing1[] = new String[] { "蓬", "任", "冲", "辅", "英", "芮", "柱", "心" };
	static String xing2[] = new String[] { "芮", "柱", "心", "蓬", "任", "冲", "辅", "英" };
	static String xing3[] = new String[] { "冲", "辅", "英", "芮", "柱", "心", "蓬", "任" };
	static String xing4[] = new String[] { "辅", "英", "芮", "柱", "心", "蓬", "任", "冲" };
	static String xing6[] = new String[] { "心", "蓬", "任", "冲", "辅", "英", "芮", "柱" };
	static String xing7[] = new String[] { "柱", "心", "蓬", "任", "冲", "辅", "英", "芮" };
	static String xing8[] = new String[] { "任", "冲", "辅", "英", "芮", "柱", "心", "蓬" };
	static String xing9[] = new String[] { "英", "芮", "柱", "心", "蓬", "任", "冲", "辅" };
	static String tiangan1[] = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };
	static String tiangan2[] = new String[] { "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸", "甲", "乙" };
	static String tiangan3[] = new String[] { "戊", "己", "庚", "辛", "壬", "癸", "甲", "乙", "丙", "丁" };
	static String tiangan4[] = new String[] { "庚", "辛", "壬", "癸", "甲", "乙", "丙", "丁", "戊", "己" };
	static String tiangan5[] = new String[] { "壬", "癸", "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛" };
	public LinkedHashMap<String, String> basexing = new LinkedHashMap<String, String>();
	{
		basexing.put("one", "蓬");
		basexing.put("two", "芮");
		basexing.put("three", "冲");
		basexing.put("four", "辅");
		basexing.put("five", "禽");
		basexing.put("six", "心");
		basexing.put("seven", "柱");
		basexing.put("eight", "任");
		basexing.put("nine", "英");
	}


	@RequestMapping("/qimenDate")
	public Qimen qimenDate(@RequestBody AllDate allDate, HttpServletRequest request) {
		System.out.println("this ip is "+getIpAddr(request));
		System.out.println(allDate.getDay());
		Qimen qimen = new Qimen();
		Sizhu sizhu = new Sizhu();
		if(allDate.getYear() != null) {
			sizhu = getSizhu(allDate);
		}else {
			sizhu = getSizhu(null);
		}
		qimen.setSizhu(sizhu);
		// 查时干空亡
		qimen.setKongwang(getKongWang(sizhu.getHours()));
		// 查日干空亡
		qimen.setRigankongwang(getKongWang(sizhu.getDay()));
		qimen.setYuegankongwang(getKongWang(sizhu.getMonth()));
		qimen.setNiangankongwang(getKongWang(sizhu.getYear()));
		// * 1.定节气以及上中下三元
		// * 2.根据几元确定几局 局数可手动传入
		Jieqi jieqi = getJieqi(allDate);
		qimen.setJieqi(jieqi);
		// * 3.判断阴阳二遁，
		jieqi = getYinYang(jieqi);
		// * 4.找到时干旬首
		qimen.setXunshou(getXunshou(sizhu));
		// 排地盘
		qimen = dipangan(qimen);
		// * 6.根据旬首定值符星，
		qimen = zhifuxing(qimen);
		// 然后排九星
		qimen = jiuxing(qimen);
		// * 5.排天盘
		qimen = tianpangan(qimen);
		// * 7.然后排八神
		qimen = bashen(qimen);

		// 定时辰数
		qimen = shichenNumber(qimen);
		// * 8.定 值使门宫，从地盘上的时柱旬首开始数，然后排八门
		qimen = paibamen(qimen);
		qimen.setNianshensha(getShensha(sizhu.getYear()));
		qimen.setYueshensha(getShensha(sizhu.getMonth()));
		qimen.setRishensha(getShensha(sizhu.getDay()));
		qimen.setShishensha(getShensha(sizhu.getHours()));


		return qimen;
	}

	// 定值使宫，排八门
	public Qimen paibamen(Qimen qimen) {
		int zhishigong = 0;
		String shiganxunshou = qimen.getXunshou().substring(2);
		// 判断地盘旬首宫
		int dipanxunshougong = 0;
		LinkedHashMap<Integer, String> dipangan = qimen.getDipangan();
		for (Entry<Integer, String> string : dipangan.entrySet()) {
			if (shiganxunshou.equals(string.getValue())) {
				dipanxunshougong = string.getKey();
			}
		}
		int shichenNumber = qimen.getSizhu().getShichenNumber();
		while (shichenNumber != 0) {
			shichenNumber--;
			if (qimen.getJieqi().getYinYang().equals("阳遁")) {
				if (shichenNumber == 0) {
					zhishigong = dipanxunshougong;
				} else {
					dipanxunshougong++;
					if (dipanxunshougong >= 10) {
						dipanxunshougong = 1;
					}
				}
			} else {
				if (shichenNumber == 0) {
					zhishigong = dipanxunshougong;
				} else {
					dipanxunshougong--;
					if (dipanxunshougong <= 0) {
						dipanxunshougong = 9;
					}
				}
			}
		}
		// 排八门
		String[] mens = null;
		if (qimen.getZhishimen().equals("休")) {
			mens = new String[] { "休", "生", "伤", "杜", "景", "死", "惊", "开" };
		} else if (qimen.getZhishimen().equals("生")) {
			mens = new String[] { "生", "伤", "杜", "景", "死", "惊", "开", "休" };
		} else if (qimen.getZhishimen().equals("伤")) {
			mens = new String[] { "伤", "杜", "景", "死", "惊", "开", "休", "生" };
		} else if (qimen.getZhishimen().equals("杜")) {
			mens = new String[] { "杜", "景", "死", "惊", "开", "休", "生", "伤" };
		} else if (qimen.getZhishimen().equals("景")) {
			mens = new String[] { "景", "死", "惊", "开", "休", "生", "伤", "杜" };
		} else if (qimen.getZhishimen().equals("死")) {
			mens = new String[] { "死", "惊", "开", "休", "生", "伤", "杜", "景" };
		} else if (qimen.getZhishimen().equals("惊")) {
			mens = new String[] { "惊", "开", "休", "生", "伤", "杜", "景", "死" };
		} else if (qimen.getZhishimen().equals("开")) {
			mens = new String[] { "开", "休", "生", "伤", "杜", "景", "死", "惊" };
		}
		LinkedHashMap<String, String> men = new LinkedHashMap<>();
		// 判断阴阳二遁
		switch (zhishigong) {
			case 1:
				men.put("one", mens[0]);
				men.put("eight", mens[1]);
				men.put("three", mens[2]);
				men.put("four", mens[3]);
				men.put("nine", mens[4]);
				men.put("two", mens[5]);
				men.put("seven", mens[6]);
				men.put("six", mens[7]);
				break;
			case 8:
				men.put("eight", mens[0]);
				men.put("three", mens[1]);
				men.put("four", mens[2]);
				men.put("nine", mens[3]);
				men.put("two", mens[4]);
				men.put("seven", mens[5]);
				men.put("six", mens[6]);
				men.put("one", mens[7]);
				break;
			case 3:
				men.put("three", mens[0]);
				men.put("four", mens[1]);
				men.put("nine", mens[2]);
				men.put("two", mens[3]);
				men.put("seven", mens[4]);
				men.put("six", mens[5]);
				men.put("one", mens[6]);
				men.put("eight", mens[7]);
				break;
			case 4:
				men.put("four", mens[0]);
				men.put("nine", mens[1]);
				men.put("two", mens[2]);
				men.put("seven", mens[3]);
				men.put("six", mens[4]);
				men.put("one", mens[5]);
				men.put("eight", mens[6]);
				men.put("three", mens[7]);
				break;
			case 9:
				men.put("nine", mens[0]);
				men.put("two", mens[1]);
				men.put("seven", mens[2]);
				men.put("six", mens[3]);
				men.put("one", mens[4]);
				men.put("eight", mens[5]);
				men.put("three", mens[6]);
				men.put("four", mens[7]);
				break;
			case 2:
				men.put("two", mens[0]);
				men.put("seven", mens[1]);
				men.put("six", mens[2]);
				men.put("one", mens[3]);
				men.put("eight", mens[4]);
				men.put("three", mens[5]);
				men.put("four", mens[6]);
				men.put("nine", mens[7]);
				break;
			case 5:
				men.put("two", mens[0]);
				men.put("seven", mens[1]);
				men.put("six", mens[2]);
				men.put("one", mens[3]);
				men.put("eight", mens[4]);
				men.put("three", mens[5]);
				men.put("four", mens[6]);
				men.put("nine", mens[7]);
				break;
			case 7:
				men.put("seven", mens[0]);
				men.put("six", mens[1]);
				men.put("one", mens[2]);
				men.put("eight", mens[3]);
				men.put("three", mens[4]);
				men.put("four", mens[5]);
				men.put("nine", mens[6]);
				men.put("two", mens[7]);
				break;
			case 6:
				men.put("six", mens[0]);
				men.put("one", mens[1]);
				men.put("eight", mens[2]);
				men.put("three", mens[3]);
				men.put("four", mens[4]);
				men.put("nine", mens[5]);
				men.put("two", mens[6]);
				men.put("seven", mens[7]);
				break;
		}
		qimen.setMen1(men);
		LinkedHashMap<Integer, String> men1 = new LinkedHashMap<>();
		// 判断阴阳二遁
		switch (zhishigong) {
			case 1:
				men1.put(1, mens[0]);
				men1.put(8, mens[1]);
				men1.put(3, mens[2]);
				men1.put(4, mens[3]);
				men1.put(9, mens[4]);
				men1.put(2, mens[5]);
				men1.put(7, mens[6]);
				men1.put(6, mens[7]);
				break;
			case 8:
				men1.put(8, mens[0]);
				men1.put(3, mens[1]);
				men1.put(4, mens[2]);
				men1.put(9, mens[3]);
				men1.put(2, mens[4]);
				men1.put(7, mens[5]);
				men1.put(6, mens[6]);
				men1.put(1, mens[7]);
				break;
			case 3:
				men1.put(3, mens[0]);
				men1.put(4, mens[1]);
				men1.put(9, mens[2]);
				men1.put(2, mens[3]);
				men1.put(7, mens[4]);
				men1.put(6, mens[5]);
				men1.put(1, mens[6]);
				men1.put(8, mens[7]);
				break;
			case 4:
				men1.put(4, mens[0]);
				men1.put(9, mens[1]);
				men1.put(2, mens[2]);
				men1.put(7, mens[3]);
				men1.put(6, mens[4]);
				men1.put(1, mens[5]);
				men1.put(8, mens[6]);
				men1.put(3, mens[7]);
				break;
			case 9:
				men1.put(9, mens[0]);
				men1.put(2, mens[1]);
				men1.put(7, mens[2]);
				men1.put(6, mens[3]);
				men1.put(1, mens[4]);
				men1.put(8, mens[5]);
				men1.put(3, mens[6]);
				men1.put(4, mens[7]);
				break;
			case 2:
				men1.put(2, mens[0]);
				men1.put(7, mens[1]);
				men1.put(6, mens[2]);
				men1.put(1, mens[3]);
				men1.put(8, mens[4]);
				men1.put(3, mens[5]);
				men1.put(4, mens[6]);
				men1.put(9, mens[7]);
				break;
			case 5:
				men1.put(2, mens[0]);
				men1.put(7, mens[1]);
				men1.put(6, mens[2]);
				men1.put(1, mens[3]);
				men1.put(8, mens[4]);
				men1.put(3, mens[5]);
				men1.put(4, mens[6]);
				men1.put(9, mens[7]);
				break;
			case 7:
				men1.put(7, mens[0]);
				men1.put(6, mens[1]);
				men1.put(1, mens[2]);
				men1.put(8, mens[3]);
				men1.put(3, mens[4]);
				men1.put(4, mens[5]);
				men1.put(9, mens[6]);
				men1.put(2, mens[7]);
				break;
			case 6:
				men1.put(6, mens[0]);
				men1.put(1, mens[1]);
				men1.put(8, mens[2]);
				men1.put(3, mens[3]);
				men1.put(4, mens[4]);
				men1.put(9, mens[5]);
				men1.put(2, mens[6]);
				men1.put(7, mens[7]);
				break;
		}
		qimen.setMen(men1);
		return qimen;
	}

	// 定时辰数
	public Qimen shichenNumber(Qimen qimen) {
		String shizhu = qimen.getSizhu().getHours();
		String tiangan = shizhu.substring(0, 1);
		int shichenNumber = 0;
		if (tiangan.equals("甲")) {
			shichenNumber = 1;
		} else if (tiangan.equals("乙")) {
			shichenNumber = 2;
		} else if (tiangan.equals("丙")) {
			shichenNumber = 3;
		} else if (tiangan.equals("丁")) {
			shichenNumber = 4;
		} else if (tiangan.equals("戊")) {
			shichenNumber = 5;
		} else if (tiangan.equals("己")) {
			shichenNumber = 6;
		} else if (tiangan.equals("庚")) {
			shichenNumber = 7;
		} else if (tiangan.equals("辛")) {
			shichenNumber = 8;
		} else if (tiangan.equals("壬")) {
			shichenNumber = 9;
		} else if (tiangan.equals("癸")) {
			shichenNumber = 10;
		}
		qimen.getSizhu().setShichenNumber(shichenNumber);
		return qimen;
	}

	// 排八神
	public Qimen bashen(Qimen qimen) {
		LinkedHashMap<String, String> shen = new LinkedHashMap<>();
		LinkedHashMap<Integer, String> xing = qimen.getXing();
		// 判断阴阳二遁
		if (qimen.getJieqi().getYinYang().equals("阳遁")) {
			switch (qimen.getZhifuxinggong()) {
				case 1:
					shen.put("one", yangshen[0]);
					shen.put("eight", yangshen[1]);
					shen.put("three", yangshen[2]);
					shen.put("four", yangshen[3]);
					shen.put("nine", yangshen[4]);
					shen.put("two", yangshen[5]);
					shen.put("seven", yangshen[6]);
					shen.put("six", yangshen[7]);
					break;
				case 8:
					shen.put("eight", yangshen[0]);
					shen.put("three", yangshen[1]);
					shen.put("four", yangshen[2]);
					shen.put("nine", yangshen[3]);
					shen.put("two", yangshen[4]);
					shen.put("seven", yangshen[5]);
					shen.put("six", yangshen[6]);
					shen.put("one", yangshen[7]);
					break;
				case 3:
					shen.put("three", yangshen[0]);
					shen.put("four", yangshen[1]);
					shen.put("nine", yangshen[2]);
					shen.put("two", yangshen[3]);
					shen.put("seven", yangshen[4]);
					shen.put("six", yangshen[5]);
					shen.put("one", yangshen[6]);
					shen.put("eight", yangshen[7]);
					break;
				case 4:
					shen.put("four", yangshen[0]);
					shen.put("nine", yangshen[1]);
					shen.put("two", yangshen[2]);
					shen.put("seven", yangshen[3]);
					shen.put("six", yangshen[4]);
					shen.put("one", yangshen[5]);
					shen.put("eight", yangshen[6]);
					shen.put("three", yangshen[7]);
					break;
				case 9:
					shen.put("nine", yangshen[0]);
					shen.put("two", yangshen[1]);
					shen.put("seven", yangshen[2]);
					shen.put("six", yangshen[3]);
					shen.put("one", yangshen[4]);
					shen.put("eight", yangshen[5]);
					shen.put("three", yangshen[6]);
					shen.put("four", yangshen[7]);
					break;
				case 2:
					shen.put("two", yangshen[0]);
					shen.put("seven", yangshen[1]);
					shen.put("six", yangshen[2]);
					shen.put("one", yangshen[3]);
					shen.put("eight", yangshen[4]);
					shen.put("three", yangshen[5]);
					shen.put("four", yangshen[6]);
					shen.put("nine", yangshen[7]);
					break;
				case 5:
					shen.put("two", yangshen[0]);
					shen.put("seven", yangshen[1]);
					shen.put("six", yangshen[2]);
					shen.put("one", yangshen[3]);
					shen.put("eight", yangshen[4]);
					shen.put("three", yangshen[5]);
					shen.put("four", yangshen[6]);
					shen.put("nine", yangshen[7]);
					break;
				case 7:
					shen.put("seven", yangshen[0]);
					shen.put("six", yangshen[1]);
					shen.put("one", yangshen[2]);
					shen.put("eight", yangshen[3]);
					shen.put("three", yangshen[4]);
					shen.put("four", yangshen[5]);
					shen.put("nine", yangshen[6]);
					shen.put("two", yangshen[7]);
					break;
				case 6:
					shen.put("six", yangshen[0]);
					shen.put("one", yangshen[1]);
					shen.put("eight", yangshen[2]);
					shen.put("three", yangshen[3]);
					shen.put("four", yangshen[4]);
					shen.put("nine", yangshen[5]);
					shen.put("two", yangshen[6]);
					shen.put("seven", yangshen[7]);
					break;
			}
		} else {
			switch (qimen.getZhifuxinggong()) {
				case 1:
					shen.put("one", yinshen[0]);
					shen.put("eight", yinshen[1]);
					shen.put("three", yinshen[2]);
					shen.put("four", yinshen[3]);
					shen.put("nine", yinshen[4]);
					shen.put("two", yinshen[5]);
					shen.put("seven", yinshen[6]);
					shen.put("six", yinshen[7]);
					break;
				case 8:
					shen.put("eight", yinshen[0]);
					shen.put("three", yinshen[1]);
					shen.put("four", yinshen[2]);
					shen.put("nine", yinshen[3]);
					shen.put("two", yinshen[4]);
					shen.put("seven", yinshen[5]);
					shen.put("six", yinshen[6]);
					shen.put("one", yinshen[7]);
					break;
				case 3:
					shen.put("three", yinshen[0]);
					shen.put("four", yinshen[1]);
					shen.put("nine", yinshen[2]);
					shen.put("two", yinshen[3]);
					shen.put("seven", yinshen[4]);
					shen.put("six", yinshen[5]);
					shen.put("one", yinshen[6]);
					shen.put("eight", yinshen[7]);
					break;
				case 4:
					shen.put("four", yinshen[0]);
					shen.put("nine", yinshen[1]);
					shen.put("two", yinshen[2]);
					shen.put("seven", yinshen[3]);
					shen.put("six", yinshen[4]);
					shen.put("one", yinshen[5]);
					shen.put("eight", yinshen[6]);
					shen.put("three", yinshen[7]);
					break;
				case 9:
					shen.put("nine", yinshen[0]);
					shen.put("two", yinshen[1]);
					shen.put("seven", yinshen[2]);
					shen.put("six", yinshen[3]);
					shen.put("one", yinshen[4]);
					shen.put("eight", yinshen[5]);
					shen.put("three", yinshen[6]);
					shen.put("four", yinshen[7]);
					break;
				case 2:
					shen.put("two", yinshen[0]);
					shen.put("seven", yinshen[1]);
					shen.put("six", yinshen[2]);
					shen.put("one", yinshen[3]);
					shen.put("eight", yinshen[4]);
					shen.put("three", yinshen[5]);
					shen.put("four", yinshen[6]);
					shen.put("nine", yinshen[7]);
					break;
				case 5:
					shen.put("two", yinshen[0]);
					shen.put("seven", yinshen[1]);
					shen.put("six", yinshen[2]);
					shen.put("one", yinshen[3]);
					shen.put("eight", yinshen[4]);
					shen.put("three", yinshen[5]);
					shen.put("four", yinshen[6]);
					shen.put("nine", yinshen[7]);
					break;
				case 7:
					shen.put("seven", yinshen[0]);
					shen.put("six", yinshen[1]);
					shen.put("one", yinshen[2]);
					shen.put("eight", yinshen[3]);
					shen.put("three", yinshen[4]);
					shen.put("four", yinshen[5]);
					shen.put("nine", yinshen[6]);
					shen.put("two", yinshen[7]);
					break;
				case 6:
					shen.put("six", yinshen[0]);
					shen.put("one", yinshen[1]);
					shen.put("eight", yinshen[2]);
					shen.put("three", yinshen[3]);
					shen.put("four", yinshen[4]);
					shen.put("nine", yinshen[5]);
					shen.put("two", yinshen[6]);
					shen.put("seven", yinshen[7]);
					break;
			}
		}
		qimen.setShen1(shen);
		LinkedHashMap<Integer, String> shen1 = new LinkedHashMap<>();
		// 判断阴阳二遁
		if (qimen.getJieqi().getYinYang().equals("阳遁")) {
			switch (qimen.getZhifuxinggong()) {
				case 1:
					shen1.put(1, yangshen[0]);
					shen1.put(8, yangshen[1]);
					shen1.put(3, yangshen[2]);
					shen1.put(4, yangshen[3]);
					shen1.put(9, yangshen[4]);
					shen1.put(2, yangshen[5]);
					shen1.put(7, yangshen[6]);
					shen1.put(6, yangshen[7]);
					break;
				case 8:
					shen1.put(8, yangshen[0]);
					shen1.put(3, yangshen[1]);
					shen1.put(4, yangshen[2]);
					shen1.put(9, yangshen[3]);
					shen1.put(2, yangshen[4]);
					shen1.put(7, yangshen[5]);
					shen1.put(6, yangshen[6]);
					shen1.put(1, yangshen[7]);
					break;
				case 3:
					shen1.put(3, yangshen[0]);
					shen1.put(4, yangshen[1]);
					shen1.put(9, yangshen[2]);
					shen1.put(2, yangshen[3]);
					shen1.put(7, yangshen[4]);
					shen1.put(6, yangshen[5]);
					shen1.put(1, yangshen[6]);
					shen1.put(8, yangshen[7]);
					break;
				case 4:
					shen1.put(4, yangshen[0]);
					shen1.put(9, yangshen[1]);
					shen1.put(2, yangshen[2]);
					shen1.put(7, yangshen[3]);
					shen1.put(6, yangshen[4]);
					shen1.put(1, yangshen[5]);
					shen1.put(8, yangshen[6]);
					shen1.put(3, yangshen[7]);
					break;
				case 9:
					shen1.put(9, yangshen[0]);
					shen1.put(2, yangshen[1]);
					shen1.put(7, yangshen[2]);
					shen1.put(6, yangshen[3]);
					shen1.put(1, yangshen[4]);
					shen1.put(8, yangshen[5]);
					shen1.put(3, yangshen[6]);
					shen1.put(4, yangshen[7]);
					break;
				case 2:
					shen1.put(2, yangshen[0]);
					shen1.put(7, yangshen[1]);
					shen1.put(6, yangshen[2]);
					shen1.put(1, yangshen[3]);
					shen1.put(8, yangshen[4]);
					shen1.put(3, yangshen[5]);
					shen1.put(4, yangshen[6]);
					shen1.put(9, yangshen[7]);
					break;
				case 5:
					shen1.put(2, yangshen[0]);
					shen1.put(7, yangshen[1]);
					shen1.put(6, yangshen[2]);
					shen1.put(1, yangshen[3]);
					shen1.put(8, yangshen[4]);
					shen1.put(3, yangshen[5]);
					shen1.put(4, yangshen[6]);
					shen1.put(9, yangshen[7]);
					break;
				case 7:
					shen1.put(7, yangshen[0]);
					shen1.put(6, yangshen[1]);
					shen1.put(1, yangshen[2]);
					shen1.put(8, yangshen[3]);
					shen1.put(3, yangshen[4]);
					shen1.put(4, yangshen[5]);
					shen1.put(9, yangshen[6]);
					shen1.put(2, yangshen[7]);
					break;
				case 6:
					shen1.put(6, yangshen[0]);
					shen1.put(1, yangshen[1]);
					shen1.put(8, yangshen[2]);
					shen1.put(3, yangshen[3]);
					shen1.put(4, yangshen[4]);
					shen1.put(9, yangshen[5]);
					shen1.put(2, yangshen[6]);
					shen1.put(7, yangshen[7]);
					break;
			}
		} else {
			switch (qimen.getZhifuxinggong()) {
				case 1:
					shen1.put(1, yinshen[0]);
					shen1.put(8, yinshen[1]);
					shen1.put(3, yinshen[2]);
					shen1.put(4, yinshen[3]);
					shen1.put(9, yinshen[4]);
					shen1.put(2, yinshen[5]);
					shen1.put(7, yinshen[6]);
					shen1.put(6, yinshen[7]);
					break;
				case 8:
					shen1.put(8, yinshen[0]);
					shen1.put(3, yinshen[1]);
					shen1.put(4, yinshen[2]);
					shen1.put(9, yinshen[3]);
					shen1.put(2, yinshen[4]);
					shen1.put(7, yinshen[5]);
					shen1.put(6, yinshen[6]);
					shen1.put(1, yinshen[7]);
					break;
				case 3:
					shen1.put(3, yinshen[0]);
					shen1.put(4, yinshen[1]);
					shen1.put(9, yinshen[2]);
					shen1.put(2, yinshen[3]);
					shen1.put(7, yinshen[4]);
					shen1.put(6, yinshen[5]);
					shen1.put(1, yinshen[6]);
					shen1.put(8, yinshen[7]);
					break;
				case 4:
					shen1.put(4, yinshen[0]);
					shen1.put(9, yinshen[1]);
					shen1.put(2, yinshen[2]);
					shen1.put(7, yinshen[3]);
					shen1.put(6, yinshen[4]);
					shen1.put(1, yinshen[5]);
					shen1.put(8, yinshen[6]);
					shen1.put(3, yinshen[7]);
					break;
				case 9:
					shen1.put(9, yinshen[0]);
					shen1.put(2, yinshen[1]);
					shen1.put(7, yinshen[2]);
					shen1.put(6, yinshen[3]);
					shen1.put(1, yinshen[4]);
					shen1.put(8, yinshen[5]);
					shen1.put(3, yinshen[6]);
					shen1.put(4, yinshen[7]);
					break;
				case 2:
					shen1.put(2, yinshen[0]);
					shen1.put(7, yinshen[1]);
					shen1.put(6, yinshen[2]);
					shen1.put(1, yinshen[3]);
					shen1.put(8, yinshen[4]);
					shen1.put(3, yinshen[5]);
					shen1.put(4, yinshen[6]);
					shen1.put(9, yinshen[7]);
					break;
				case 5:
					shen1.put(2, yinshen[0]);
					shen1.put(7, yinshen[1]);
					shen1.put(6, yinshen[2]);
					shen1.put(1, yinshen[3]);
					shen1.put(8, yinshen[4]);
					shen1.put(3, yinshen[5]);
					shen1.put(4, yinshen[6]);
					shen1.put(9, yinshen[7]);
					break;
				case 7:
					shen1.put(7, yinshen[0]);
					shen1.put(6, yinshen[1]);
					shen1.put(1, yinshen[2]);
					shen1.put(8, yinshen[3]);
					shen1.put(3, yinshen[4]);
					shen1.put(4, yinshen[5]);
					shen1.put(9, yinshen[6]);
					shen1.put(2, yinshen[7]);
					break;
				case 6:
					shen1.put(6, yinshen[0]);
					shen1.put(1, yinshen[1]);
					shen1.put(8, yinshen[2]);
					shen1.put(3, yinshen[3]);
					shen1.put(4, yinshen[4]);
					shen1.put(9, yinshen[5]);
					shen1.put(2, yinshen[6]);
					shen1.put(7, yinshen[7]);
					break;
			}
		}
		qimen.setShen(shen1);
		return qimen;
	}

	// 排天盘干
	public Qimen tianpangan(Qimen qimen) {
		LinkedHashMap<String, String> tianpangan = new LinkedHashMap<>();
		LinkedHashMap<Integer, String> dipangan = qimen.getDipangan();
		LinkedHashMap<Integer, String> xing = qimen.getXing();
		// 我需要天盘干本位宫的数
		for (int i = 1; i < 10; i++) {
			String indexs = "";
			if(i==1){
				indexs = "one";
			}
			if(i==2){
				indexs = "two";
			}
			if(i==3){
				indexs = "three";
			}
			if(i==4){
				indexs = "four";
			}
			if(i==5){
				indexs = "five";
			}
			if(i==6){
				indexs = "six";
			}
			if(i==7){
				indexs = "seven";
			}
			if(i==8){
				indexs = "eight";
			}
			if(i==9){
				indexs = "nine";
			}
			if (i >= 5 && i <= 5) {
				continue;
			}
			String tianpanxing = xing.get(i);// 得到当前宫位的天盘星
			// 找本位宫
			if (tianpanxing.equals("蓬")) {
				tianpangan.put(indexs, dipangan.get(1));
			} else if (tianpanxing.equals("任")) {
				tianpangan.put(indexs, dipangan.get(8));
			} else if (tianpanxing.equals("冲")) {
				tianpangan.put(indexs, dipangan.get(3));
			} else if (tianpanxing.equals("辅")) {
				tianpangan.put(indexs, dipangan.get(4));
			} else if (tianpanxing.equals("英")) {
				tianpangan.put(indexs, dipangan.get(9));
			} else if (tianpanxing.equals("芮")) {
				tianpangan.put(indexs, dipangan.get(2));
			} else if (tianpanxing.equals("柱")) {
				tianpangan.put(indexs, dipangan.get(7));
			} else if (tianpanxing.equals("心")) {
				tianpangan.put(indexs, dipangan.get(6));
			}
		}
		qimen.setTianpangan1(tianpangan);
		LinkedHashMap<Integer, String> tianpangan1 = new LinkedHashMap<>();
		// 我需要天盘干本位宫的数
		for (int i = 1; i < 10; i++) {
			if (i >= 5 && i <= 5) {
				continue;
			}
			String tianpanxing = xing.get(i);// 得到当前宫位的天盘星
			// 找本位宫
			if (tianpanxing.equals("蓬")) {
				tianpangan1.put(i, dipangan.get(1));
			} else if (tianpanxing.equals("任")) {
				tianpangan1.put(i, dipangan.get(8));
			} else if (tianpanxing.equals("冲")) {
				tianpangan1.put(i, dipangan.get(3));
			} else if (tianpanxing.equals("辅")) {
				tianpangan1.put(i, dipangan.get(4));
			} else if (tianpanxing.equals("英")) {
				tianpangan1.put(i, dipangan.get(9));
			} else if (tianpanxing.equals("芮")) {
				tianpangan1.put(i, dipangan.get(2));
			} else if (tianpanxing.equals("柱")) {
				tianpangan1.put(i, dipangan.get(7));
			} else if (tianpanxing.equals("心")) {
				tianpangan1.put(i, dipangan.get(6));
			}
		}
		qimen.setTianpangan(tianpangan1);
		return qimen;
	}

	// 排九星
	public Qimen jiuxing(Qimen qimen) {
		int zhifuxinggong = 0;
		String shigan = qimen.getSizhu().getHours().substring(0, 1);
		String shizhu = qimen.getSizhu().getHours();
		if(shizhu.equals("甲子")) {
			shigan = "戊";
		}else if(shizhu.equals("甲戌")) {
			shigan = "己";
		}else if(shizhu.equals("甲申")) {
			shigan = "庚";
		}else if(shizhu.equals("甲午")) {
			shigan = "辛";
		}else if(shizhu.equals("甲辰")) {
			shigan = "壬";
		}else if(shizhu.equals("甲寅")) {
			shigan = "癸";
		}
		LinkedHashMap<Integer, String> dipangan = qimen.getDipangan();
		LinkedHashMap<String, String> xing = new LinkedHashMap<>();
		for (Entry<Integer, String> string : dipangan.entrySet()) {
			if (shigan.equals(string.getValue())) {
				zhifuxinggong = string.getKey();
				qimen.setZhifuxinggong(zhifuxinggong);
			}
			;
		}
		// 知道了值符星在哪个宫位，其他以此类推就可以
		switch (zhifuxinggong) {
			case 1:
				xing.put("one", qimen.getXingshuzu()[0]);
				xing.put("eight", qimen.getXingshuzu()[1]);
				xing.put("three", qimen.getXingshuzu()[2]);
				xing.put("four", qimen.getXingshuzu()[3]);
				xing.put("nine", qimen.getXingshuzu()[4]);
				xing.put("two", qimen.getXingshuzu()[5]);
				xing.put("seven", qimen.getXingshuzu()[6]);
				xing.put("six", qimen.getXingshuzu()[7]);
				break;
			case 8:
				xing.put("eight", qimen.getXingshuzu()[0]);
				xing.put("three", qimen.getXingshuzu()[1]);
				xing.put("four", qimen.getXingshuzu()[2]);
				xing.put("nine", qimen.getXingshuzu()[3]);
				xing.put("two", qimen.getXingshuzu()[4]);
				xing.put("seven", qimen.getXingshuzu()[5]);
				xing.put("six", qimen.getXingshuzu()[6]);
				xing.put("one", qimen.getXingshuzu()[7]);
				break;
			case 3:
				xing.put("three", qimen.getXingshuzu()[0]);
				xing.put("four", qimen.getXingshuzu()[1]);
				xing.put("nine", qimen.getXingshuzu()[2]);
				xing.put("two", qimen.getXingshuzu()[3]);
				xing.put("seven", qimen.getXingshuzu()[4]);
				xing.put("six", qimen.getXingshuzu()[5]);
				xing.put("one", qimen.getXingshuzu()[6]);
				xing.put("eight", qimen.getXingshuzu()[7]);
				break;
			case 4:
				xing.put("four", qimen.getXingshuzu()[0]);
				xing.put("nine", qimen.getXingshuzu()[1]);
				xing.put("two", qimen.getXingshuzu()[2]);
				xing.put("seven", qimen.getXingshuzu()[3]);
				xing.put("six", qimen.getXingshuzu()[4]);
				xing.put("one", qimen.getXingshuzu()[5]);
				xing.put("eight", qimen.getXingshuzu()[6]);
				xing.put("three", qimen.getXingshuzu()[7]);
				break;
			case 9:
				xing.put("nine", qimen.getXingshuzu()[0]);
				xing.put("two", qimen.getXingshuzu()[1]);
				xing.put("seven", qimen.getXingshuzu()[2]);
				xing.put("six", qimen.getXingshuzu()[3]);
				xing.put("one", qimen.getXingshuzu()[4]);
				xing.put("eight", qimen.getXingshuzu()[5]);
				xing.put("three", qimen.getXingshuzu()[6]);
				xing.put("four", qimen.getXingshuzu()[7]);
				break;
			case 2:
				xing.put("two", qimen.getXingshuzu()[0]);
				xing.put("seven", qimen.getXingshuzu()[1]);
				xing.put("six", qimen.getXingshuzu()[2]);
				xing.put("one", qimen.getXingshuzu()[3]);
				xing.put("eight", qimen.getXingshuzu()[4]);
				xing.put("three", qimen.getXingshuzu()[5]);
				xing.put("four", qimen.getXingshuzu()[6]);
				xing.put("nine", qimen.getXingshuzu()[7]);
				break;
			case 5:
				xing.put("two", qimen.getXingshuzu()[0]);
				xing.put("seven", qimen.getXingshuzu()[1]);
				xing.put("six", qimen.getXingshuzu()[2]);
				xing.put("one", qimen.getXingshuzu()[3]);
				xing.put("eight", qimen.getXingshuzu()[4]);
				xing.put("three", qimen.getXingshuzu()[5]);
				xing.put("four", qimen.getXingshuzu()[6]);
				xing.put("nine", qimen.getXingshuzu()[7]);
				break;
			case 7:
				xing.put("seven", qimen.getXingshuzu()[0]);
				xing.put("six", qimen.getXingshuzu()[1]);
				xing.put("one", qimen.getXingshuzu()[2]);
				xing.put("eight", qimen.getXingshuzu()[3]);
				xing.put("three", qimen.getXingshuzu()[4]);
				xing.put("four", qimen.getXingshuzu()[5]);
				xing.put("nine", qimen.getXingshuzu()[6]);
				xing.put("two", qimen.getXingshuzu()[7]);
				break;
			case 6:
				xing.put("six", qimen.getXingshuzu()[0]);
				xing.put("one", qimen.getXingshuzu()[1]);
				xing.put("eight", qimen.getXingshuzu()[2]);
				xing.put("three", qimen.getXingshuzu()[3]);
				xing.put("four", qimen.getXingshuzu()[4]);
				xing.put("nine", qimen.getXingshuzu()[5]);
				xing.put("two", qimen.getXingshuzu()[6]);
				xing.put("seven", qimen.getXingshuzu()[7]);
				break;
		}
		qimen.setXing1(xing);
		LinkedHashMap<Integer, String> xing1 = new LinkedHashMap<>();
		for (Entry<Integer, String> string : dipangan.entrySet()) {
			if (shigan.equals(string.getValue())) {
				zhifuxinggong = string.getKey();
				qimen.setZhifuxinggong(zhifuxinggong);
			}
			;
		}
		// 知道了值符星在哪个宫位，其他以此类推就可以
		switch (zhifuxinggong) {
			case 1:
				xing1.put(1, qimen.getXingshuzu()[0]);
				xing1.put(8, qimen.getXingshuzu()[1]);
				xing1.put(3, qimen.getXingshuzu()[2]);
				xing1.put(4, qimen.getXingshuzu()[3]);
				xing1.put(9, qimen.getXingshuzu()[4]);
				xing1.put(2, qimen.getXingshuzu()[5]);
				xing1.put(7, qimen.getXingshuzu()[6]);
				xing1.put(6, qimen.getXingshuzu()[7]);
				break;
			case 8:
				xing1.put(8, qimen.getXingshuzu()[0]);
				xing1.put(3, qimen.getXingshuzu()[1]);
				xing1.put(4, qimen.getXingshuzu()[2]);
				xing1.put(9, qimen.getXingshuzu()[3]);
				xing1.put(2, qimen.getXingshuzu()[4]);
				xing1.put(7, qimen.getXingshuzu()[5]);
				xing1.put(6, qimen.getXingshuzu()[6]);
				xing1.put(1, qimen.getXingshuzu()[7]);
				break;
			case 3:
				xing1.put(3, qimen.getXingshuzu()[0]);
				xing1.put(4, qimen.getXingshuzu()[1]);
				xing1.put(9, qimen.getXingshuzu()[2]);
				xing1.put(2, qimen.getXingshuzu()[3]);
				xing1.put(7, qimen.getXingshuzu()[4]);
				xing1.put(6, qimen.getXingshuzu()[5]);
				xing1.put(1, qimen.getXingshuzu()[6]);
				xing1.put(8, qimen.getXingshuzu()[7]);
				break;
			case 4:
				xing1.put(4, qimen.getXingshuzu()[0]);
				xing1.put(9, qimen.getXingshuzu()[1]);
				xing1.put(2, qimen.getXingshuzu()[2]);
				xing1.put(7, qimen.getXingshuzu()[3]);
				xing1.put(6, qimen.getXingshuzu()[4]);
				xing1.put(1, qimen.getXingshuzu()[5]);
				xing1.put(8, qimen.getXingshuzu()[6]);
				xing1.put(3, qimen.getXingshuzu()[7]);
				break;
			case 9:
				xing1.put(9, qimen.getXingshuzu()[0]);
				xing1.put(2, qimen.getXingshuzu()[1]);
				xing1.put(7, qimen.getXingshuzu()[2]);
				xing1.put(6, qimen.getXingshuzu()[3]);
				xing1.put(1, qimen.getXingshuzu()[4]);
				xing1.put(8, qimen.getXingshuzu()[5]);
				xing1.put(3, qimen.getXingshuzu()[6]);
				xing1.put(4, qimen.getXingshuzu()[7]);
				break;
			case 2:
				xing1.put(2, qimen.getXingshuzu()[0]);
				xing1.put(7, qimen.getXingshuzu()[1]);
				xing1.put(6, qimen.getXingshuzu()[2]);
				xing1.put(1, qimen.getXingshuzu()[3]);
				xing1.put(8, qimen.getXingshuzu()[4]);
				xing1.put(3, qimen.getXingshuzu()[5]);
				xing1.put(4, qimen.getXingshuzu()[6]);
				xing1.put(9, qimen.getXingshuzu()[7]);
				break;
			case 5:
				xing1.put(2, qimen.getXingshuzu()[0]);
				xing1.put(7, qimen.getXingshuzu()[1]);
				xing1.put(6, qimen.getXingshuzu()[2]);
				xing1.put(1, qimen.getXingshuzu()[3]);
				xing1.put(8, qimen.getXingshuzu()[4]);
				xing1.put(3, qimen.getXingshuzu()[5]);
				xing1.put(4, qimen.getXingshuzu()[6]);
				xing1.put(9, qimen.getXingshuzu()[7]);
				break;
			case 7:
				xing1.put(7, qimen.getXingshuzu()[0]);
				xing1.put(6, qimen.getXingshuzu()[1]);
				xing1.put(1, qimen.getXingshuzu()[2]);
				xing1.put(8, qimen.getXingshuzu()[3]);
				xing1.put(3, qimen.getXingshuzu()[4]);
				xing1.put(4, qimen.getXingshuzu()[5]);
				xing1.put(9, qimen.getXingshuzu()[6]);
				xing1.put(2, qimen.getXingshuzu()[7]);
				break;
			case 6:
				xing1.put(6, qimen.getXingshuzu()[0]);
				xing1.put(1, qimen.getXingshuzu()[1]);
				xing1.put(8, qimen.getXingshuzu()[2]);
				xing1.put(3, qimen.getXingshuzu()[3]);
				xing1.put(4, qimen.getXingshuzu()[4]);
				xing1.put(9, qimen.getXingshuzu()[5]);
				xing1.put(2, qimen.getXingshuzu()[6]);
				xing1.put(7, qimen.getXingshuzu()[7]);
				break;
		}
		qimen.setXing(xing1);
		return qimen;
	}

	// 定值符星
	public Qimen zhifuxing(Qimen qimen) {
		String xunshou = qimen.getXunshou().substring(2);
		int gongwei = 0;
		LinkedHashMap<Integer, String> dipangan = qimen.getDipangan();
		for (Entry<Integer, String> string : dipangan.entrySet()) {
			if (xunshou.equals(string.getValue())) {
				gongwei = string.getKey();
				break;
			}
			;
		}
		switch (gongwei) {
			case 1:
				qimen.setZhishimen("休");
				qimen.setZhifuxing("蓬");
				qimen.setXingshuzu(xing1);
				break;
			case 2:
				qimen.setZhishimen("死");
				qimen.setZhifuxing("芮");
				qimen.setXingshuzu(xing2);
				break;
			case 3:
				qimen.setZhishimen("伤");
				qimen.setZhifuxing("冲");
				qimen.setXingshuzu(xing3);
				break;
			case 4:
				qimen.setZhishimen("杜");
				qimen.setZhifuxing("辅");
				qimen.setXingshuzu(xing4);
				break;
			case 5:
				qimen.setZhishimen("死");
				qimen.setZhifuxing("禽");
				qimen.setXingshuzu(xing2);
				break;
			case 6:
				qimen.setZhishimen("开");
				qimen.setZhifuxing("心");
				qimen.setXingshuzu(xing6);
				break;
			case 7:
				qimen.setZhishimen("惊");
				qimen.setZhifuxing("柱");
				qimen.setXingshuzu(xing7);
				break;
			case 8:
				qimen.setZhishimen("生");
				qimen.setZhifuxing("任");
				qimen.setXingshuzu(xing8);
				break;
			case 9:
				qimen.setZhishimen("景");
				qimen.setZhifuxing("英");
				qimen.setXingshuzu(xing9);
				break;
		}
		return qimen;
	}

	// 排地盘
	public Qimen dipangan(Qimen qimen) {
		LinkedHashMap<String, String> dipangan = new LinkedHashMap<>();
		if (qimen.getJieqi().getYinYang().equals("阳遁")) {
			switch (qimen.getJieqi().getJuNumber()) {
				case 1:
					dipangan.put("one", "戊");
					dipangan.put("two", "己");
					dipangan.put("three", "庚");
					dipangan.put("four", "辛");
					dipangan.put("five", "壬");
					dipangan.put("six", "癸");
					dipangan.put("seven", "丁");
					dipangan.put("eight", "丙");
					dipangan.put("nine", "乙");
					break;
				case 2:
					dipangan.put("two", "戊");
					dipangan.put("three", "己");
					dipangan.put("four", "庚");
					dipangan.put("five", "辛");
					dipangan.put("six", "壬");
					dipangan.put("seven", "癸");
					dipangan.put("eight", "丁");
					dipangan.put("nine", "丙");
					dipangan.put("one", "乙");
					break;
				case 3:
					dipangan.put("three", "戊");
					dipangan.put("four", "己");
					dipangan.put("five", "庚");
					dipangan.put("six", "辛");
					dipangan.put("seven", "壬");
					dipangan.put("eight", "癸");
					dipangan.put("nine", "丁");
					dipangan.put("one", "丙");
					dipangan.put("two", "乙");
					break;
				case 4:
					dipangan.put("four", "戊");
					dipangan.put("five", "己");
					dipangan.put("six", "庚");
					dipangan.put("seven", "辛");
					dipangan.put("eight", "壬");
					dipangan.put("nine", "癸");
					dipangan.put("one", "丁");
					dipangan.put("two", "丙");
					dipangan.put("three", "乙");
					break;
				case 5:
					dipangan.put("five", "戊");
					dipangan.put("six", "己");
					dipangan.put("seven", "庚");
					dipangan.put("eight", "辛");
					dipangan.put("nine", "壬");
					dipangan.put("one", "癸");
					dipangan.put("two", "丁");
					dipangan.put("three", "丙");
					dipangan.put("four", "乙");
					break;
				case 6:
					dipangan.put("six", "戊");
					dipangan.put("seven", "己");
					dipangan.put("eight", "庚");
					dipangan.put("nine", "辛");
					dipangan.put("one", "壬");
					dipangan.put("two", "癸");
					dipangan.put("three", "丁");
					dipangan.put("four", "丙");
					dipangan.put("five", "乙");
					break;
				case 7:
					dipangan.put("seven", "戊");
					dipangan.put("eight", "己");
					dipangan.put("nine", "庚");
					dipangan.put("one", "辛");
					dipangan.put("two", "壬");
					dipangan.put("three", "癸");
					dipangan.put("four", "丁");
					dipangan.put("five", "丙");
					dipangan.put("six", "乙");
					break;
				case 8:
					dipangan.put("eight", "戊");
					dipangan.put("nine", "己");
					dipangan.put("one", "庚");
					dipangan.put("two", "辛");
					dipangan.put("three", "壬");
					dipangan.put("four", "癸");
					dipangan.put("five", "丁");
					dipangan.put("six", "丙");
					dipangan.put("seven", "乙");
					break;
				case 9:
					dipangan.put("nine", "戊");
					dipangan.put("one", "己");
					dipangan.put("two", "庚");
					dipangan.put("three", "辛");
					dipangan.put("four", "壬");
					dipangan.put("five", "癸");
					dipangan.put("six", "丁");
					dipangan.put("seven", "丙");
					dipangan.put("eight", "乙");
					break;

			}

		} else {
			switch (qimen.getJieqi().getJuNumber()) {
				case 1:
					dipangan.put("one", "戊");
					dipangan.put("nine", "己");
					dipangan.put("eight", "庚");
					dipangan.put("seven", "辛");
					dipangan.put("six", "壬");
					dipangan.put("five", "癸");
					dipangan.put("four", "丁");
					dipangan.put("three", "丙");
					dipangan.put("two", "乙");
					break;
				case 2:
					dipangan.put("two", "戊");
					dipangan.put("one", "己");
					dipangan.put("nine", "庚");
					dipangan.put("eight", "辛");
					dipangan.put("seven", "壬");
					dipangan.put("six", "癸");
					dipangan.put("five", "丁");
					dipangan.put("four", "丙");
					dipangan.put("three", "乙");
					break;
				case 3:
					dipangan.put("three", "戊");
					dipangan.put("two", "己");
					dipangan.put("one", "庚");
					dipangan.put("nine", "辛");
					dipangan.put("eight", "壬");
					dipangan.put("seven", "癸");
					dipangan.put("six", "丁");
					dipangan.put("five", "丙");
					dipangan.put("four", "乙");
					break;
				case 4:
					dipangan.put("four", "戊");
					dipangan.put("three", "己");
					dipangan.put("two", "庚");
					dipangan.put("one", "辛");
					dipangan.put("nine", "壬");
					dipangan.put("eight", "癸");
					dipangan.put("seven", "丁");
					dipangan.put("six", "丙");
					dipangan.put("five", "乙");
					break;
				case 5:
					dipangan.put("five", "戊");
					dipangan.put("four", "己");
					dipangan.put("three", "庚");
					dipangan.put("two", "辛");
					dipangan.put("one", "壬");
					dipangan.put("nine", "癸");
					dipangan.put("eight", "丁");
					dipangan.put("seven", "丙");
					dipangan.put("six", "乙");
					break;
				case 6:
					dipangan.put("six", "戊");
					dipangan.put("five", "己");
					dipangan.put("four", "庚");
					dipangan.put("three", "辛");
					dipangan.put("two", "壬");
					dipangan.put("one", "癸");
					dipangan.put("nine", "丁");
					dipangan.put("eight", "丙");
					dipangan.put("seven", "乙");
					break;
				case 7:
					dipangan.put("seven", "戊");
					dipangan.put("six", "己");
					dipangan.put("five", "庚");
					dipangan.put("four", "辛");
					dipangan.put("three", "壬");
					dipangan.put("two", "癸");
					dipangan.put("one", "丁");
					dipangan.put("nine", "丙");
					dipangan.put("eight", "乙");
					break;
				case 8:
					dipangan.put("eight", "戊");
					dipangan.put("seven", "己");
					dipangan.put("six", "庚");
					dipangan.put("five", "辛");
					dipangan.put("four", "壬");
					dipangan.put("three", "癸");
					dipangan.put("two", "丁");
					dipangan.put("one", "丙");
					dipangan.put("nine", "乙");
					break;
				case 9:
					dipangan.put("nine", "戊");
					dipangan.put("eight", "己");
					dipangan.put("seven", "庚");
					dipangan.put("six", "辛");
					dipangan.put("five", "壬");
					dipangan.put("four", "癸");
					dipangan.put("three", "丁");
					dipangan.put("two", "丙");
					dipangan.put("one", "乙");
					break;

			}
		}
		qimen.setDipangan1(dipangan);
		LinkedHashMap<Integer, String> dipangan1 = new LinkedHashMap<>();
		if (qimen.getJieqi().getYinYang().equals("阳遁")) {
			switch (qimen.getJieqi().getJuNumber()) {
				case 1:
					dipangan1.put(1, "戊");
					dipangan1.put(2, "己");
					dipangan1.put(3, "庚");
					dipangan1.put(4, "辛");
					dipangan1.put(5, "壬");
					dipangan1.put(6, "癸");
					dipangan1.put(7, "丁");
					dipangan1.put(8, "丙");
					dipangan1.put(9, "乙");
					break;
				case 2:
					dipangan1.put(2, "戊");
					dipangan1.put(3, "己");
					dipangan1.put(4, "庚");
					dipangan1.put(5, "辛");
					dipangan1.put(6, "壬");
					dipangan1.put(7, "癸");
					dipangan1.put(8, "丁");
					dipangan1.put(9, "丙");
					dipangan1.put(1, "乙");
					break;
				case 3:
					dipangan1.put(3, "戊");
					dipangan1.put(4, "己");
					dipangan1.put(5, "庚");
					dipangan1.put(6, "辛");
					dipangan1.put(7, "壬");
					dipangan1.put(8, "癸");
					dipangan1.put(9, "丁");
					dipangan1.put(1, "丙");
					dipangan1.put(2, "乙");
					break;
				case 4:
					dipangan1.put(4, "戊");
					dipangan1.put(5, "己");
					dipangan1.put(6, "庚");
					dipangan1.put(7, "辛");
					dipangan1.put(8, "壬");
					dipangan1.put(9, "癸");
					dipangan1.put(1, "丁");
					dipangan1.put(2, "丙");
					dipangan1.put(3, "乙");
					break;
				case 5:
					dipangan1.put(5, "戊");
					dipangan1.put(6, "己");
					dipangan1.put(7, "庚");
					dipangan1.put(8, "辛");
					dipangan1.put(9, "壬");
					dipangan1.put(1, "癸");
					dipangan1.put(2, "丁");
					dipangan1.put(3, "丙");
					dipangan1.put(4, "乙");
					break;
				case 6:
					dipangan1.put(6, "戊");
					dipangan1.put(7, "己");
					dipangan1.put(8, "庚");
					dipangan1.put(9, "辛");
					dipangan1.put(1, "壬");
					dipangan1.put(2, "癸");
					dipangan1.put(3, "丁");
					dipangan1.put(4, "丙");
					dipangan1.put(5, "乙");
					break;
				case 7:
					dipangan1.put(7, "戊");
					dipangan1.put(8, "己");
					dipangan1.put(9, "庚");
					dipangan1.put(1, "辛");
					dipangan1.put(2, "壬");
					dipangan1.put(3, "癸");
					dipangan1.put(4, "丁");
					dipangan1.put(5, "丙");
					dipangan1.put(6, "乙");
					break;
				case 8:
					dipangan1.put(8, "戊");
					dipangan1.put(9, "己");
					dipangan1.put(1, "庚");
					dipangan1.put(2, "辛");
					dipangan1.put(3, "壬");
					dipangan1.put(4, "癸");
					dipangan1.put(5, "丁");
					dipangan1.put(6, "丙");
					dipangan1.put(7, "乙");
					break;
				case 9:
					dipangan1.put(9, "戊");
					dipangan1.put(1, "己");
					dipangan1.put(2, "庚");
					dipangan1.put(3, "辛");
					dipangan1.put(4, "壬");
					dipangan1.put(5, "癸");
					dipangan1.put(6, "丁");
					dipangan1.put(7, "丙");
					dipangan1.put(8, "乙");
					break;

			}

		} else {
			switch (qimen.getJieqi().getJuNumber()) {
				case 1:
					dipangan1.put(1, "戊");
					dipangan1.put(9, "己");
					dipangan1.put(8, "庚");
					dipangan1.put(7, "辛");
					dipangan1.put(6, "壬");
					dipangan1.put(5, "癸");
					dipangan1.put(4, "丁");
					dipangan1.put(3, "丙");
					dipangan1.put(2, "乙");
					break;
				case 2:
					dipangan1.put(2, "戊");
					dipangan1.put(1, "己");
					dipangan1.put(9, "庚");
					dipangan1.put(8, "辛");
					dipangan1.put(7, "壬");
					dipangan1.put(6, "癸");
					dipangan1.put(5, "丁");
					dipangan1.put(4, "丙");
					dipangan1.put(3, "乙");
					break;
				case 3:
					dipangan1.put(3, "戊");
					dipangan1.put(2, "己");
					dipangan1.put(1, "庚");
					dipangan1.put(9, "辛");
					dipangan1.put(8, "壬");
					dipangan1.put(7, "癸");
					dipangan1.put(6, "丁");
					dipangan1.put(5, "丙");
					dipangan1.put(4, "乙");
					break;
				case 4:
					dipangan1.put(4, "戊");
					dipangan1.put(3, "己");
					dipangan1.put(2, "庚");
					dipangan1.put(1, "辛");
					dipangan1.put(9, "壬");
					dipangan1.put(8, "癸");
					dipangan1.put(7, "丁");
					dipangan1.put(6, "丙");
					dipangan1.put(5, "乙");
					break;
				case 5:
					dipangan1.put(5, "戊");
					dipangan1.put(4, "己");
					dipangan1.put(3, "庚");
					dipangan1.put(2, "辛");
					dipangan1.put(1, "壬");
					dipangan1.put(9, "癸");
					dipangan1.put(8, "丁");
					dipangan1.put(7, "丙");
					dipangan1.put(6, "乙");
					break;
				case 6:
					dipangan1.put(6, "戊");
					dipangan1.put(5, "己");
					dipangan1.put(4, "庚");
					dipangan1.put(3, "辛");
					dipangan1.put(2, "壬");
					dipangan1.put(1, "癸");
					dipangan1.put(9, "丁");
					dipangan1.put(8, "丙");
					dipangan1.put(7, "乙");
					break;
				case 7:
					dipangan1.put(7, "戊");
					dipangan1.put(6, "己");
					dipangan1.put(5, "庚");
					dipangan1.put(4, "辛");
					dipangan1.put(3, "壬");
					dipangan1.put(2, "癸");
					dipangan1.put(1, "丁");
					dipangan1.put(9, "丙");
					dipangan1.put(8, "乙");
					break;
				case 8:
					dipangan1.put(8, "戊");
					dipangan1.put(7, "己");
					dipangan1.put(6, "庚");
					dipangan1.put(5, "辛");
					dipangan1.put(4, "壬");
					dipangan1.put(3, "癸");
					dipangan1.put(2, "丁");
					dipangan1.put(1, "丙");
					dipangan1.put(9, "乙");
					break;
				case 9:
					dipangan1.put(9, "戊");
					dipangan1.put(8, "己");
					dipangan1.put(7, "庚");
					dipangan1.put(6, "辛");
					dipangan1.put(5, "壬");
					dipangan1.put(4, "癸");
					dipangan1.put(3, "丁");
					dipangan1.put(2, "丙");
					dipangan1.put(1, "乙");
					break;

			}
		}
		qimen.setDipangan(dipangan1);
		return qimen;
	}

	/**
	 * 计算当前节气
	 *
	 * @return
	 */
	public Jieqi getJieqi(AllDate allDate) {

		Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00")); // 获取东八区时间
		Jieqi jieqi = new Jieqi();
		String gongliriqi = "";
		if(allDate.getYear()!=null) {
			c.set(allDate.getYear(), allDate.getMonth()-1, allDate.getDay());
			gongliriqi = allDate.getYear()+"/"+allDate.getMonth()+"/"+allDate.getDay();
		}else {
			gongliriqi = getSimpleTime(c);
		}
		RiliExample riliExample = new RiliExample();
		riliExample.or().andGongliriqiEqualTo(gongliriqi);
		Rili rili = riliMapper.selectByExample(riliExample).get(0);
		// 如果当天不是节气
		if (rili.getJieqi() == null) {
			int jieqiNumber = 0;
			for (int i = 1; i < 20; i++) {
				jieqiNumber++;
				c.add(c.DATE, -1);
				String preRiqi = getSimpleTime(c);
				RiliExample riliExampleJieqi = new RiliExample();
				riliExampleJieqi.or().andGongliriqiEqualTo(preRiqi);
				rili = riliMapper.selectByExample(riliExampleJieqi).get(0);
				// 如果当前天数不是节气
				if (rili.getJieqi() == null) {
					continue;
				} else {
					// 如果为节气上元
					if (jieqiNumber <= 5) {
						jieqi.setShangZhongXia(1);
						// 如果为节气中元
					} else if (jieqiNumber > 5 && jieqiNumber <= 10) {
						jieqi.setShangZhongXia(2);
						// 如果为节气下元
					} else if(jieqiNumber >10 && jieqiNumber <=15){
						jieqi.setShangZhongXia(3);
					}
					// 储存节气第几天
					jieqi.setJieNumber(jieqiNumber);
					// 储存节气名
					jieqi.setJieqiName(rili.getJieqi());
					// 查询第几局
					BajieExample bajieExample = new BajieExample();
					bajieExample.or().andJieqiEqualTo(jieqi.getJieqiName())
							.andShangzhongxiaEqualTo(jieqi.getShangZhongXia());
					Bajie bajie = bajieMapper.selectByExample(bajieExample).get(0);
					jieqi.setJuNumber(bajie.getJunumber());
					break;
				}
			}
		} else {
			int jieqiNumber = 1;
			// 为节气上元
			jieqi.setShangZhongXia(1);
			// 储存节气第几天
			jieqi.setJieNumber(jieqiNumber);
			// 储存节气名
			jieqi.setJieqiName(rili.getJieqi());
			// 查询第几局
			BajieExample bajieExample = new BajieExample();
			bajieExample.or().andJieqiEqualTo(jieqi.getJieqiName()).andShangzhongxiaEqualTo(jieqi.getShangZhongXia());
			Bajie bajie = bajieMapper.selectByExample(bajieExample).get(0);
			jieqi.setJuNumber(bajie.getJunumber());
		}
		return jieqi;
	}

	// 获取与数据库匹配的时间格式
	public String getSimpleTime(Calendar c) {
		int year = c.get(Calendar.YEAR); // 获取年
		int month = c.get(Calendar.MONTH) + 1; // 获取月份，0表示1月份
		int day = c.get(Calendar.DAY_OF_MONTH); // 获取当前天数
		// 修改时间为与数据库匹配的格式
		String gongliriqi = "" + year + "/" + month + "/" + day;
		return gongliriqi;
	}

	// 判断阴阳二遁
	public Jieqi getYinYang(Jieqi jieqi) {
		String jieqiName = jieqi.getJieqiName();
		if (jieqiName.equals("冬至") || jieqiName.equals("小寒") || jieqiName.equals("大寒") || jieqiName.equals("立春")
				|| jieqiName.equals("雨水") || jieqiName.equals("惊蛰") || jieqiName.equals("春分") || jieqiName.equals("清明")
				|| jieqiName.equals("谷雨") || jieqiName.equals("立夏") || jieqiName.equals("小满")
				|| jieqiName.equals("芒种")) {
			jieqi.setYinYang("阳遁");
		} else {
			jieqi.setYinYang("阴遁");
		}
		return jieqi;
	}

	// 获取四柱
	public Sizhu getSizhu(AllDate allDate) {
		int year, month, day,hours;
		if (allDate == null ) {
			Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00")); // 获取东八区时间
			year = c.get(Calendar.YEAR); // 获取年
			month = c.get(Calendar.MONTH) + 1; // 获取月份，0表示1月份
			day = c.get(Calendar.DAY_OF_MONTH); // 获取当前天数
		} else {
			year = allDate.getYear();
			month = allDate.getMonth();
			day = allDate.getDay();
			hours = allDate.getHours();
		}

		Sizhu sizhu = new Sizhu();
		String gongliriqi = "" + year + "/" + month + "/" + day;
		System.out.println("now is "+gongliriqi+"---------");
		RiliExample riliExample = new RiliExample();
		riliExample.or().andGongliriqiEqualTo(gongliriqi);
		Rili rili = riliMapper.selectByExample(riliExample).get(0);
		String shiganzhi = null;
		if(allDate == null) {
			shiganzhi = getShiChen(rili.getRiganzhi().substring(0, 1), null);
		}else {
			shiganzhi = getShiChen(rili.getRiganzhi().substring(0, 1), allDate.getHours());
		}
		rili.setShichen(shiganzhi);
		sizhu.setYear(rili.getNianganzhi());
		sizhu.setMonth(rili.getYueganzhi());
		sizhu.setDay(rili.getRiganzhi());
		sizhu.setHours(shiganzhi);
		return sizhu;
	}

	/**
	 * 获取时辰
	 *
	 * @param ritiangan
	 * @return
	 */
	public String getShiChen(String ritiangan, Integer hours) {
		Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00")); // 获取东八区时间
		if (hours == null) {
			hours = c.get(Calendar.HOUR_OF_DAY);
		}
		String shichen = "";
		int shichenId = 0;
		if (hours >= 23 || hours < 1) {
			shichenId = 1;
			shichen = "子";
		} else if (hours < 3 && hours >= 1) {
			shichenId = 2;
			shichen = "丑";
		} else if (hours < 5 && hours >= 3) {
			shichenId = 3;
			shichen = "寅";
		} else if (hours < 7 && hours >= 5) {
			shichenId = 4;
			shichen = "卯";
		} else if (hours < 9 && hours >= 7) {
			shichenId = 5;
			shichen = "辰";
		} else if (hours < 11 && hours >= 9) {
			shichenId = 6;
			shichen = "巳";
		} else if (hours < 13 && hours >= 11) {
			shichenId = 7;
			shichen = "午";
		} else if (hours < 15 && hours >= 13) {
			shichenId = 8;
			shichen = "未";
		} else if (hours < 17 && hours >= 15) {
			shichenId = 9;
			shichen = "申";
		} else if (hours < 19 && hours >= 17) {
			shichenId = 10;
			shichen = "酉";
		} else if (hours < 21 && hours >= 19) {
			shichenId = 1;
			shichen = "戌";
		} else if (hours < 23 && hours >= 21) {
			shichenId = 2;
			shichen = "亥";
		}

		if ("甲".equals(ritiangan)) {
			shichen = tiangan1[shichenId - 1] + shichen;
			return shichen;
		} else if ("乙".equals(ritiangan)) {
			shichen = tiangan2[shichenId - 1] + shichen;
			return shichen;
		} else if ("丙".equals(ritiangan)) {
			shichen = tiangan3[shichenId - 1] + shichen;
			return shichen;
		} else if ("丁".equals(ritiangan)) {
			shichen = tiangan4[shichenId - 1] + shichen;
			return shichen;
		} else if ("戊".equals(ritiangan)) {
			shichen = tiangan5[shichenId - 1] + shichen;
			return shichen;
		} else if ("己".equals(ritiangan)) {
			shichen = tiangan1[shichenId - 1] + shichen;
			return shichen;
		} else if ("庚".equals(ritiangan)) {
			shichen = tiangan2[shichenId - 1] + shichen;
			return shichen;
		} else if ("辛".equals(ritiangan)) {
			shichen = tiangan3[shichenId - 1] + shichen;
			return shichen;
		} else if ("壬".equals(ritiangan)) {
			shichen = tiangan4[shichenId - 1] + shichen;
			return shichen;
		} else if ("癸".equals(ritiangan)) {
			shichen = tiangan5[shichenId - 1] + shichen;
			return shichen;
		} else {
			return shichen;
		}
	}

	// 获取时干旬首
	public String getXunshou(Sizhu sizhu) {
		String xunshou = huajiaziMapper.selectXunshou(sizhu.getHours());
		if (xunshou.equals("甲子")) {
			xunshou = xunshou + "戊";
		} else if (xunshou.equals("甲戌")) {
			xunshou = xunshou + "己";
		} else if (xunshou.equals("甲申")) {
			xunshou = xunshou + "庚";
		} else if (xunshou.equals("甲午")) {
			xunshou = xunshou + "辛";
		} else if (xunshou.equals("甲辰")) {
			xunshou = xunshou + "壬";
		} else if (xunshou.equals("甲寅")) {
			xunshou = xunshou + "癸";
		}
		return xunshou;
	}

	// 查空亡
	public String getKongWang(String hours) {
		return huajiaziMapper.selectKongWang(hours);
	}
	private String getIpAddr(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
			if(ip.equals("127.0.0.1")){
				//根据网卡取本机配置的IP
				InetAddress inet=null;
				try {
					inet = InetAddress.getLocalHost();
				} catch (Exception e) {
					e.printStackTrace();
				}
				ip= inet.getHostAddress();
			}
		}
		// 多个代理的情况，第一个IP为客户端真实IP,多个IP按照','分割
		if(ip != null && ip.length() > 15){
			if(ip.indexOf(",")>0){
				ip = ip.substring(0,ip.indexOf(","));
			}
		}
		return ip;
	}
	public Map<String,String> getShensha(String ganzhi){
		String tiangan = ganzhi.substring(0,1);
		String dizhi = ganzhi.substring(1);
		Map<String,String> map = new HashMap<>();
		if(dizhi.equals("子")){
			map.put("破","酉");
		}else if(dizhi.equals("丑")){
			map.put("破","辰");
		}else if(dizhi.equals("寅")){
			map.put("破","亥");
		}else if(dizhi.equals("卯")){
			map.put("破","午");
		}else if(dizhi.equals("辰")){
			map.put("破","丑");
		}else if(dizhi.equals("巳")){
			map.put("破","申");
		}else if(dizhi.equals("午")){
			map.put("破","卯");
		}else if(dizhi.equals("未")){
			map.put("破","戌");
		}else if(dizhi.equals("申")){
			map.put("破","巳");
		}else if(dizhi.equals("酉")){
			map.put("破","子");
		}else if(dizhi.equals("戌")){
			map.put("破","未");
		}else if(dizhi.equals("亥")){
			map.put("破","寅");
		}
		if(tiangan.equals("甲")||tiangan.equals("戊")){
			map.put("贵人","丑  未");
		}else if(tiangan.equals("乙")||tiangan.equals("己")){
			map.put("贵人","申  子");
		}else if(tiangan.equals("丙")||tiangan.equals("丁")){
			map.put("贵人","酉  亥");
		}else if(tiangan.equals("壬")||tiangan.equals("癸")){
			map.put("贵人","卯  巳");
		}else if(tiangan.equals("庚")||tiangan.equals("辛")){
			map.put("贵人","寅  午");
		}
		if(dizhi.equals("申")||dizhi.equals("子")|| dizhi.equals("辰")){
			map.put("桃花","酉");
			map.put("马星","寅");
		}else if(dizhi.equals("巳")||dizhi.equals("酉")|| dizhi.equals("丑")){
			map.put("桃花","午");
			map.put("马星","亥");
		}else if(dizhi.equals("亥")||dizhi.equals("卯")|| dizhi.equals("未")){
			map.put("桃花","子");
			map.put("马星","巳");
		}else if(dizhi.equals("寅")||dizhi.equals("午")|| dizhi.equals("戌")){
			map.put("桃花","卯");
			map.put("马星","申");
		}
		if(tiangan.equals("甲")){
			map.put("禄神","寅");
			map.put("胎神","酉");
		}else if(tiangan.equals("乙")){
			map.put("禄神","卯");
			map.put("胎神","申");
		}else if(tiangan.equals("丙")){
			map.put("禄神","巳");
			map.put("胎神","子");
		}else if(tiangan.equals("丁")){
			map.put("禄神","午");
			map.put("胎神","亥");
		}else if(tiangan.equals("戊")){
			map.put("禄神","巳");
			map.put("胎神","子");
		}else if(tiangan.equals("己")){
			map.put("禄神","午");
			map.put("胎神","亥");
		}else if(tiangan.equals("庚")){
			map.put("禄神","申");
			map.put("胎神","卯");
		}else if(tiangan.equals("辛")){
			map.put("禄神","酉");
			map.put("胎神","寅");
		}else if(tiangan.equals("壬")){
			map.put("禄神","亥");
			map.put("胎神","午");
		}else if(tiangan.equals("癸")){
			map.put("禄神","子");
			map.put("胎神","巳");
		}

		return map;
	}
	 
}
